import 'package:awak/common/routers/router_pages.dart';
import 'package:awak/common/data/data_initializer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:beamer/beamer.dart';
import 'package:awak/bloc/provider/bloc_provider.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:awak/page/main.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // 初始化应用数据
  await DataInitializer().initializeAllData();

  runApp(
    AwakBlocProvider(
      child: BlocProvider(
        create: (_) => TabIndexCubit(),
        child: const MyApp(),
      ),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(414, 896),
      minTextAdapt: true,
      builder: (context, child) {
        return MaterialApp.router(
          debugShowCheckedModeBanner: false,
          title: 'Awak',
          theme: ThemeData(
            useMaterial3: true,
            colorScheme: ColorScheme.fromSeed(
              seedColor: const Color(0xFFD3F524),
              primary: const Color(0xFFD3F524),
              secondary: const Color(0xFFFEF463),
            ),
            appBarTheme: const AppBarTheme(
              backgroundColor: Colors.transparent,
              elevation: 0,
            ),
          ),
          routerDelegate: routerDelegate,
          routeInformationParser: BeamerParser(),
        );
      },
    );
  }
}
